<template>
	<view class="content" v-if="pageInit">
		<calculator :totalPrice="totalPrice" @submit='submit'></calculator>
	</view>
</template>

<script>
	import calculator from '../components/calculator/index.vue'
	let that = null
	const api = require("@/static/js/api.js")
	const utils = require("@/static/js/utils.js")
	export default {
		components: {
			calculator
		},
		data() {
			return {
                totalPrice:'',
                pageInit: false,
				debounceFlag: false
            }
		},
		onLoad(options) {
			that = this
            if (options.totalPrice) {
				this.totalPrice = this.totalPrice.toString() 
			}else{
				this.totalPrice = ""
			}
			
            this.pageInit = true
            console.log("totalPrice1",this.totalPrice)
		},
		methods: {
			submit(obj, type) {
				// console.log(obj)
				this.createCalculator(obj)

			},
			
			createCalculator(obj) {
			    let that = this
				if (!this.debounceFlag){
					this.debounceFlag = true
					api.createCalculator({
					    param: {
					        data: JSON.stringify(obj),
					    }
					}).then(res => {
					    console.log(res)
					    if (res.success) {  
							uni.navigateTo({
								url: '/pages/calculator/result/index?id=' + res.data 
							})
					    }
					}).finally(e=>{
						this.debounceFlag = false
					})
				}
			    
			},
		}
	}
</script>

<style>
	page{
		background-color: #f8f8f8;
	}
</style>
